<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->

<mat-card appearance="outlined" class="card">
  <div class="card__header">
    <img class="card__header__logo" src="/assets/gravitee-logo-dark-blue.png" alt="Gravitee.io" />
    <div class="card__header__title">Confirm your account</div>
    <div class="card__header__subtitle">to access to the APIM Console</div>
  </div>

  <form class="card__form" *ngIf="signUpConfirmForm && !signUpConfirmSuccess" [formGroup]="signUpConfirmForm" (ngSubmit)="signUpConfirm()">
    <mat-form-field class="card__form__input">
      <mat-label>First name</mat-label>
      <input matInput type="text" formControlName="firstName" [autofocus]="signUpConfirmForm.get('firstName').enabled" />
      <mat-error *ngIf="signUpConfirmForm.get('firstName').hasError('required')">First name is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input">
      <mat-label>Last name</mat-label>
      <input matInput type="text" formControlName="lastName" />
      <mat-error *ngIf="signUpConfirmForm.get('lastName').hasError('required')">Last name is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input">
      <mat-label>Email</mat-label>
      <input matInput type="email" formControlName="email" />
      <mat-error *ngIf="signUpConfirmForm.get('email').hasError('required')">Email is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input">
      <mat-label>Password</mat-label>
      <input matInput type="password" formControlName="password" [autofocus]="signUpConfirmForm.get('firstName').disabled" />
      <mat-error *ngIf="signUpConfirmForm.get('password').hasError('required')">Password is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input">
      <mat-label>Confirm password</mat-label>
      <input matInput type="password" formControlName="confirmPassword" />
      <mat-error *ngIf="signUpConfirmForm.get('confirmPassword').hasError('required')">Confirm password is required.</mat-error>
    </mat-form-field>

    <div *ngIf="signUpConfirmForm.hasError('passwordNotMatch')" class="card__form__error">
      <mat-error>Password and confirm password must be the same.</mat-error>
    </div>

    <button type="submit" class="card__form__button" mat-raised-button [disabled]="signUpConfirmForm.invalid || signUpConfirmInProgress">
      <mat-icon svgIcon="gio:login"></mat-icon>
      Sign up
    </button>

    <p class="card__form__goTo">I have already an account! <a routerLink="/_login">Sign in</a></p>
  </form>

  <ng-container *ngIf="signUpConfirmSuccess">
    <gio-banner-success>
      Account confirmed
      <div gioBannerAction>
        <button mat-raised-button color="primary" routerLink="/_login">Sign in</button>
      </div>
    </gio-banner-success>
  </ng-container>

  <ng-container *ngIf="signUpConfirmError">
    <gio-banner-error>
      {{ signUpConfirmError }}
      <span gioBannerBody>Contact your administrator if the problem persists.</span>
    </gio-banner-error>
    <p class="card__form__signIn">Go to <a routerLink="/_login">Sign in</a></p>
  </ng-container>
</mat-card>
